//
//  TOSConfig.m
//  shmetroPIP
//
//  Created by 宁校航 on 17/7/13.
//  Copyright © 2017年 宁校航. All rights reserved.
//  unity2018

//是否为测试环境 0为正式环境 1为测试环境 2为杭海城际项目
#define DEBUGENV     1


#import "TOSConfig.h"

@implementation TOSConfig

static TOSConfig *instance = nil;

#pragma mark - 单例模式初始化方法`
+(id)allocWithZone:(NSZone *)zone
{
    @synchronized(self)
    {
        if(instance==nil)
        {
            instance=[super allocWithZone:zone];
            
            return instance;
        }
    }
    return nil;
}

#pragma mark - 单例模式初始化
+(TOSConfig *)sharedInstance
{
    if(!instance)
    {
        instance=[[self alloc] init];
        [instance initVariables];
        
//        //测试环境
//        instance.webAddress = @"http://ip3.tztos.com:8097";
//        instance.fileWebAddress = @"http://ip2.tztos.com:8098";
//        instance.shareUrl = @"http://home.tztos.com/piprefactoring/";
//        instance.sharePicName = @"QRCode";
//        //正式环境
////        instance.webAddress = @"http://ip3.tztos.com:8108";
////        instance.fileWebAddress = @"http://ip2.tztos.com:8099";
////        instance.shareUrl = @"http://ip2.tztos.com:8233/PIPdownload";
////        instance.sharePicName = @"QRCode";
        
        
        if(DEBUGENV == 1)
        {
            instance.webAddress = @"http://192.168.5.253:8080";
            instance.fileWebAddress = @"http://ip2.tztos.com:8098";
//            instance.shareUrl = @"http://home.tztos.com/piprefactoring/";
            instance.shareUrl = @"http://ip2.tztos.com:8233/PIPdownload";
            instance.sharePicName = @"QRCode";
        }
        
        instance.needInsertArray = [[NSMutableArray alloc] init];
    }
    return instance;
}

#pragma mark - 单例内容初始化
-(void)initVariables
{
    //db file
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSFileManager *fileMgr=[NSFileManager defaultManager];
    
    NSString *dir=[paths objectAtIndex: 0];
    self.homeDir=dir;
    
    self.localDir=[dir stringByAppendingPathComponent:@"LocalFile"];
    if(![fileMgr fileExistsAtPath:self.localDir])
    {
        [fileMgr createDirectoryAtPath:self.localDir withIntermediateDirectories:YES attributes:nil error:nil];
    }
}

#pragma mark - 获取屏幕宽度与标尺屏幕（iPhone6）宽度比例
+(CGFloat)getWidthScale
{
    return [[UIScreen mainScreen] bounds].size.width/750.0f;
}

+(CGFloat)getFontWidthScale
{
    CGFloat scale = [[UIScreen mainScreen] bounds].size.width/750.0f;
    if (scale>0.7) {
        return 0.7;
    }
    else
    {
        return scale;
    }
}

#pragma mark - 获取服务器接口地址
+(NSString *)getWebServiceUrl
{
//    //测试环境
//    return [NSString stringWithFormat:@"%@/%@",[TOSConfig getWebAddress],@"webservice_pip_refactoring/api/MoService"];
//    //正式环境
////    return [NSString stringWithFormat:@"%@/%@",[TOSConfig getWebAddress],@"webservice_pip_new/api/MoService"];
    if(DEBUGENV == 1)
    {
//        return [NSString stringWithFormat:@"%@/%@",[TOSConfig getWebAddress],@"webservice_pip_refactoring/api/MoService"];
        return [TOSConfig getWebAddress];
    }


}

#pragma mark - 获取服务器地址
+(NSString *)getWebAddress
{
    return [TOSConfig sharedInstance].webAddress;
}

#pragma mark - 获取文件服务器地址
+(NSString *)getFileWebAddress
{
    return [TOSConfig sharedInstance].fileWebAddress;
}

#pragma mark - 获取文件服务webService接口地址
+(NSString *)getFileWebServiceUrl
{
//    //测试环境
//    return [NSString stringWithFormat:@"%@/%@",[TOSConfig getFileWebAddress],@"fileservice_pip_refactoring/api"];
//    //正式环境
////    return [NSString stringWithFormat:@"%@/%@",[TOSConfig getFileWebAddress],@"fileservice_pip_new/api"];
    

    
    if(DEBUGENV == 1)
    {
        return [NSString stringWithFormat:@"%@/%@",[TOSConfig getFileWebAddress],@"fileservice_pip_refactoring/api"];
    }
}

@end
